<?php

/**
 * 资讯管理
 * 
 */
namespace Index\Controller;
use Lib\Controller;
class IndexController extends Controller {
	
	private $news_model,$types;
	
	public function _initialize(){
		$this->news_model = getInstance('News\Model\NewsModel');		
		$this->types = $this->getNewsType();
	}

	public function index() {
		$news = $this->news_model->where('type=2')->limit('0,10')->select();
		$guides = $this->news_model->where('type=31')->limit('0,8')->select();
		$laws = $this->news_model->where('type=8')->limit('0,5')->select();
		$demos = $this->news_model->where('type=30')->limit('0,5')->select();
		$tables = $this->news_model->where('type=20')->limit('0,5')->select();
		$this->assign('news',$news);
		$this->assign('guides',$guides);
		$this->assign('laws',$laws);
		$this->assign('demos',$demos);
		$this->assign('tables',$tables);
		$this->assign('types',$this->types);
		$this->display('Index/View/index.php');
	}

	public function news() {
		$id = $_GET['id'];
		$news = $this->news_model->where('type='.$id)->select();
		$this->assign('news',$news);
		$this->assign('types',$this->types);
		$this->assign('type',$this->types[$id]);
		$this->display('Index/View/news.php');
	} 

	public function detail() {
		$id = $_GET['id'];
		$news = $this->news_model->where('id='.$id)->find();
		$this->assign('news',$news);
		$this->assign('types',$this->types);
		$this->display('Index/View/detail.php');
	} 
	
	/**
	 * 获取资讯类型
	 */
	protected function getNewsType(){
		if($news_types = getInstance('News\Model\NewsTypeModel')->field('id,title')->select()){
			foreach($news_types as $v){
				$data[$v['id']] = $v['title'];
			}
		}
		return $data;
	}

}
?>